package com.xinyun.server.protocol.receive;

import com.xinyun.server.protocol.ProtocolData;
import com.xinyun.server.protocol.ProtocolDataHeader;
import com.xinyun.server.util.Utils;
import io.netty.buffer.ByteBuf;

/**
 * Created by bubusy on 16/5/22.
 */
public class LeakWarnData extends ProtocolData {


    public int pid;
    public int currentLeak;
    public String time;


    public LeakWarnData(ProtocolDataHeader header, ByteBuf bodyBytes) {

        super(header, bodyBytes);
    }

    public static LeakWarnData parseFromProtocolData(ProtocolData protocolData) {
        LeakWarnData obj = null;
        try {

            obj = new LeakWarnData(protocolData.getHeader(), protocolData.getBodyBytes());
            ByteBuf body = protocolData.getBodyBytes().copy();
            //body.order(Unpooled.LITTLE_ENDIAN);
            obj.pid = body.readShortLE();
            obj.currentLeak = body.readShortLE();
            obj.time = Utils.parseTime(body);

        } catch (Exception e) {
            return null;
        }


        return obj;
    }

}
